import java.util.*;

public class Rezolvare {
	@SuppressWarnings("rawtypes")
	Stack btStack = new Stack();
	Operator op[] = {new UmpleC1(), new GolesteC1(), new Goleste12(), new UmpleC2(), new GolesteC2(), new Goleste21()};
	
	@SuppressWarnings("unchecked")
	public void solving(Cana stare) {
		//Expandez un nou nod
		Cana s = expand(stare);
		//Daca nodul expandat nu se mai gaseste in stiva starilor atunci
		if(!search(s)) {
			//Adaug noul nod in stiva
			btStack.push(s);
			
			//Verific daca noul nod adaugat in stiva este solutie
			if(solutie(s))
				return;
			else {//daca noul nod nu este solutie atunci continui cautarea
				for(int i=0; i<6; i++)
					op[i].skip=false;
				solving(s);
			}
		}
		else //in caz ca nodul expandat este deja in stiva
			if(btStack.size()!=0){
				Cana c=(Cana)btStack.elementAt(btStack.size()-1);
				solving(c);
			}
	}
	
	public Cana expand(Cana stare){
		Cana temp = new Cana(stare.x, stare.y);
		
		if(op[0].valabil(temp) && op[0].skip==false) {
			temp=op[0].execute(temp);
			op[0].skip=true;
		}
		else if(op[1].valabil(temp) && op[1].skip == false) {
			temp=op[1].execute(temp);
			op[1].skip=true;
		}
		else if(op[2].valabil(temp) && op[2].skip == false) {
			temp=op[2].execute(temp);
			op[2].skip=true;
		}
		else if(op[3].valabil(temp) && op[3].skip == false) {
			temp=op[3].execute(temp);
			op[3].skip=true;
		}
		else if(op[4].valabil(temp) && op[4].skip == false) {
			temp=op[4].execute(temp);
			op[4].skip=true;
		}
		else if(op[5].valabil(temp) && op[5].skip == false) {
			temp=op[5].execute(temp);
			op[5].skip=true;
		}
		
		return temp;
}
	public boolean solutie(Cana s){
		boolean r=false;
		if(s.getY()==2)
		r=true;
		return r;
		}
		public void print(){
		if(btStack.size()!=0){
		int n= btStack.size();
		Cana sol[]=new Cana[n];
		for(int i=n-1;i>0;i--)
		sol[i]=(Cana)btStack.pop();
		for(int i=0;i<n;i++)
		System.out.println(sol[i]);
		}
		}
		@SuppressWarnings("unchecked")
		public void init(){
		btStack.push(new Cana(0,0));
		}
		public boolean search(Cana s){
			boolean r=false;
			for(int i=0;i<btStack.size();i++)
				if(((Cana)btStack.elementAt(i)).equals(s)){
					return true;
				}
			return r;
		}
}